/**
* ...
* @author Default
* @version 0.1
*/

package org.hive.sequence
{
	import flash.events.Event;
    import org.hive.events.SequenceEvent;
	import flash.events.Event;

	public class CloseSequence extends Sequence
	{
		//private var __active:Boolean = false;

        /**
        *
        * @param	name
        * @param	sequences
        */
		public function CloseSequence( name:String, sequences:Array=null )
		{
			super( name, sequences );
        }

        /**
        * @private
        * @param	value
        * @return
        */
        public override function set complete( value:Boolean ):void
        {
            super.complete = value;

            if( __complete && !__active ){
                var event:SequenceEvent = new SequenceEvent( SequenceEvent.ON_COMPLETE );
                dispatchEvent( event );
            }
        }
		
        /**
        * @private
        * @param	e
        * @return
        */
		internal override function handleSequenceEnd( e:Event ):void
		{
            super.handleSequenceEnd( e );

			var event:SequenceEvent = new SequenceEvent( SequenceEvent.ON_COMPLETE, null, false, null, e );
			dispatchEvent( event );
		}
		
		public override function slice( startIndex:Number=0, endIndex:Number=16777215 ):*
		{
			var seq:CloseSequence 		= new CloseSequence( __name, __REPOSITORY.slice( startIndex, endIndex ) );
			seq.completeTriggerName 	= __completeEventName;
			seq.completeTriggerSource 	= __completeEventSource;

			if( __active ) {
				if( seq.length ) kill( );
			}

			return seq;
		}
		
		/**
		* @private
		*/
		public override function toString():String
		{
			var returnString:String = "[CloseSequence \n \t" + __name ;
			returnString += "\t\t" + __REPOSITORY.toString( ) + " ]";
			
			return returnString;
		}
	}
	
}
